package eliminate.view;

import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;

@SuppressWarnings("serial")
public class MyButton extends JButton {
	Image bt_img_armed = null;
	Image bt_img_rollover = null;
	Image bt_img_normal = null;
	
	public MyButton(Image bt_img_normal,
			Image bt_img_armed,
			Image bt_img_rollover){
		this.bt_img_armed = bt_img_armed;
		this.bt_img_normal = bt_img_normal;
		this.bt_img_rollover = bt_img_rollover;
		
		setBorder(null);
		this.setContentAreaFilled(false);
	}
	

	@Override
	protected void paintComponent(Graphics g) {
		if(getModel().isArmed()){
			g.drawImage(bt_img_armed, 0, 0, this.getWidth(), this.getHeight(), this);
		}
		else if(getModel().isRollover()){
			g.drawImage(bt_img_rollover, 0, 0, this.getWidth(), this.getHeight(), this);
		}
		else{
			g.drawImage(bt_img_normal, 0, 0, this.getWidth(), this.getHeight(), this);
		}
	}
	
	public static JButton makeButton(String pic_path, String pic_down, String pic_hover)
			throws IOException {
		Image btton_normal = ImageIO.read(new File(pic_path));
		Image button_down = ImageIO.read(new File(pic_down));
		Image button_hover = ImageIO.read(new File(pic_hover));
		return new MyButton(btton_normal, button_down, button_hover);
	}
	
	public static void main(String[] args) {
		JFrame jf = new JFrame();
		
		jf.setSize(800, 600);
		jf.setLayout(new FlowLayout());
		jf.setVisible(true);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
